<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/22
 * Time: 10:09
 */

namespace App\Http\Controllers\Service;


use App\Http\Controllers\CommonController;
use App\Http\Model\ProductMainInfoModel;
use App\Http\Model\ProductModel;
use Symfony\Component\HttpFoundation\Request;


class ProductController extends CommonController {

    private $product = null;
    private $ProductMainInfo = null;

    function __construct() {
        $this->product          = new ProductModel();
        $this->ProductMainInfo  = new ProductMainInfoModel();
    }

    public function getProducts(Request $request,$cateId) {

        if(!$request->isMethod("Get") || empty($cateId)){
            exit(responseJson(1,'请求方式不正确'));
        }
        $productInfo = $this->product->getProductsInfoByCateId($cateId,
            ['ProId','ProName','ProSummary','ProPrice','ProPreview']);
        return view('product',['products'=>$productInfo]);
    }

    public function getProductInfo($pmiId) {
        $productInfo     = $this->product->getProductById($pmiId);
        $productMainInfo = $this->ProductMainInfo->findProductById($pmiId);

        return view('productMainInfo',[
            'product' => $productInfo[0],
            'productMainInfo' => $productMainInfo
        ]);

    }


}